$(function(){

	var sidebarOculta = false;

	// Menu de Herramientas
	$(function() {
		$("#tabsHerramientas").tabs();
		//$("#tabsHerramientas").tabs().find(".ui-tabs-nav").sortable({axis:'x'});
	});

	// Menu Accordeon
	$("#accordeon").accordion({ 
		header: "h3",
		autoHeight: false,
		collapsible: true
	});

	// Calendario
	$(function() {
		$("#calendario").datepicker();
	});

	// Menu tree dentro del menu acordeon
	var simpleTreeCollection;
	$(document).ready(function(){
		simpleTreeCollection = $('.simpleTree').simpleTree({
			autoclose: true,
			afterClick:function(node){
				//alert("text-"+$('span:first',node).text());
			},
			afterDblClick:function(node){
				//alert("text-"+$('span:first',node).text());
			},
			afterMove:function(destination, source, pos){
				//alert("destination-"+destination.attr('id')+" source-"+source.attr('id')+" pos-"+pos);
			},
			afterAjax:function()
			{
				//alert('Loaded');
			},
			animate:true
			//,docToFolderConvert:true
		});
	});
	
	// Data grid
	$(document).ready(function() {
		$('#example').dataTable( {
			"bProcessing": true,
			/*"bServerSide": true,*/
			"sAjaxSource": 'contenidoTabla.txt'
		} );
	} );
	
	// ****************************************** POPUP
	/* PANTALLA DE DIALOGO QUE MUESTRA UN POPUP */
	// Dialog
	$(function() {
		$('#dialog').dialog({
			autoOpen: false,
			width: 400,
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
					$(this).dialog("close"); 
				} 
			}
		});
	} );

	// Dialog Link
	$(function() {
		$('#dialog_link').click(function(){
			$('#dialog').dialog('open');
			return false;
		});	
	} );
	
	// ****************************************** EFECTO
	//run the currently selected effect
	function runEffect(){
		//get effect type from 
		var selectedEffect = "slide";
		
		//most effect types need no options passed by default
		//var options = {};
		
		if (sidebarOculta == false){
			var options = { to: {width: 100} };
			//run the effect
			$("#effect").hide(selectedEffect,options,250,esconderSidebar);
			sidebarOculta = true;
		}else{
			mostrarSidebar();
			$("#effect").show(selectedEffect,options,250);
			sidebarOculta = false;
		}
	};
	
	function esconderSidebar(){
		var navegacionObj = {
			"margin-left": "-6px"
		}
		$("#buttonHide").text(">>");
		$('#navegacion').css(navegacionObj);
	};
	
	//mostrarSidebar function to bring a hidden box back
	function mostrarSidebar(){
		$('#navegacion').css("margin-left", "230px");
		$("#buttonHide").text("<<");
	};
	
	//set effect from select menu value
	$("#buttonHide").click(function() {
		runEffect();
		return false;
	});
	
	
});